package com.x.ant.service;

import com.x.ant.dao.MoneyDao;
import com.x.ant.model.Money;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MoneyService extends BaseService {
    @Autowired
    private MoneyDao moneyDao;

    public List<Money> selectMoneyList(Money money) {
        try {
            return moneyDao.selectMoneyList(money);
        } catch (Exception e){
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    public int selectMoneyNum(Money money) {
        try {
            return moneyDao.selectMoneyNum(money);
        } catch (Exception e){
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    public Money insertMoney(Money money) {
        try {
            money.setMoneyCreateTime(this.getDate(0));
            return this.insert(money);
        } catch (Exception e){
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    public void updateMoney(Money money) {
        try {
            this.update(money);
        } catch (Exception e){
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

}
